﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using Common;

namespace DAL
{
    /// <summary>
    ///  区位勘察表
    /// </summary>
    public class LocationDal : BaseDal<Model.EALocation>
    {
        public override string tablename
        {
            get { return "EALocation"; }
        }

        public override Dictionary<string, bool> PKName
        {
            get
            {
                Dictionary<string, bool> dic = new Dictionary<string, bool>();
                dic.Add("location_id", true);
                return dic;
            }
        }
        /// <summary>
        /// 区位勘察反填
        /// </summary>
        /// <param name="pro"></param>
        /// <returns></returns>
         public List<EALocation> GetListByPro(string pro)
        {
            string sql = "select * from EALocation where ProjectNumber='"+pro+"' ";
             DataTable dt= Common.DBHelp.GetDataSet(sql);
             List<EALocation> list = new List<Model.EALocation>();
             foreach(DataRow dr in dt.Rows)
             {
                 EALocation loca = new Model.EALocation();
                 loca.location_Community = dr["location_Community"].ToString();
                 loca.location_Convenient = (int)dr["location_Convenient"];
                 loca.location_Degree = (int)dr["location_Degree"];
                 loca.location_East = dr["location_East"].ToString();
                 loca.location_Explain = dr["location_Explain"].ToString();
                 loca.location_Facilities = dr["location_Facilities"].ToString();
                 loca.location_Humanity = dr["location_Humanity"].ToString();
                 loca.location_Mature = (int)dr["location_Mature"];
                 loca.location_North = dr["location_North"].ToString();
                 loca.location_Position = (int)dr["location_Position"];
                 loca.location_Quality = (int)dr["location_Quality"];
                 loca.location_South = (string)dr["location_South"];
                 loca.location_Supporting = (int)dr["location_Supporting"];
                 loca.location_Traffic = (string)dr["location_Traffic"];
                 loca.location_West = (string)dr["location_West"];
                 list.Add(loca);
             }
             return list;
        }
        /// <summary>
        /// 判断项目号是否唯一
        /// </summary>
        /// <param name="pro"></param>
        /// <returns></returns>
         public int GetCount(string pro)
         {
             string sql = "select count(*) from EALocation where ProjectNumber='"+pro+"' ";
             return  (int)Common.DBHelp.GetExecuteScalar(sql);
         }
         /// <summary>
         /// 根据项目编号修改
         /// </summary>
         /// <param name="t"></param>
         /// <param name="id"></param>
         /// <returns></returns>
         public bool Update(EALocation loca)
         {
             string sql = @"UPDATE [House].[dbo].[EALocation]SET [Location_East] = '" + loca.location_East + " ',[Location_West] = '" + loca.location_West + "',[Location_North] = '" + loca.location_North + "',[Location_South] = '" + loca.location_South + "',[Location_Position] = '" + loca.location_Position + "',[Location_Traffic] ='" + loca.location_Traffic + "',[Location_Convenient] = '" + loca.location_Convenient + "' ,[Location_Humanity] = '" + loca.location_Humanity + "',[Location_Quality] = '" + loca.location_Quality + "',[Location_Community] = '" + loca.location_Community + "',[Location_Mature] = '" + loca.location_Mature + "',[Location_Facilities] = '" + loca.location_Facilities + "',[Location_Degree] = '" + loca.location_Degree + "' ,[Location_Supporting] = '" + loca.location_Supporting + "',[Location_Explain] ='" + loca.location_Explain + "' WHERE ProjectNumber='" + loca.projectNumber + "'";
             return DBHelp.GetExecuteNonQuery(sql);
         }
    }
}
